package longrise.phone.com.bjjt_henan.compensate;

import android.content.Context;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.main.ServiceCenterView;

/**
 * 保险报案后，温馨提示，选择线上，还是线下定损，Created by Administrator on 2016/5/12.
 */

public class PromptAfterInsuranceReportView extends LFView implements View.OnClickListener {
    private String singlecar;
    private Context context = null;
    private View view = null;
    private EntityBean[] CreateAgreementbean;
    private String appCaseno;
    private LinearLayout hn_btn_back;
    private TextView tv_title;
    private LinearLayout onlineLayout;
    private LinearLayout cpscenterLayout;
    private int type = 0;

    public PromptAfterInsuranceReportView(Context c, EntityBean[] CreateAgreementbean, String appCaseno) {
        super(c);
        this.context = c;
        this.CreateAgreementbean = CreateAgreementbean;
        this.appCaseno = appCaseno;
    }

    public PromptAfterInsuranceReportView(Context c, EntityBean[] CreateAgreementbean, String appCaseno, String singlecar) {
        super(c);
        this.context = c;
        this.CreateAgreementbean = CreateAgreementbean;
        this.appCaseno = appCaseno;
        this.singlecar = singlecar;
    }

    public void setTypes(int type) {
        this.type = type;
    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter fp = new FormParameter();
        fp.setShowtitle(false);
        return fp;
    }

    @Override
    public void refresh() {

    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void init() {
        initView();
        regEvent(true);
    }

    private void initView() {
        view = View.inflate(context, R.layout.view_promptafterinsurancereport, null);
        hn_btn_back = (LinearLayout) view.findViewById(R.id.hn_btn_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_title.setText("保险理赔");
        onlineLayout = (LinearLayout) view.findViewById(R.id.insurancereport_layout_online);
        cpscenterLayout = (LinearLayout) view.findViewById(R.id.insurancereport_layout_cpscenter);

        showFlash();
    }

    //显示动画效果
    private void showFlash() {
        TextView dot = (TextView) view.findViewById(R.id.tv_flash);
        //缩放动画
        Animation scale = new ScaleAnimation(1.0f, 0.8f, 1.0f, 0.8f, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scale.setDuration(800);
        scale.setRepeatMode(Animation.REVERSE);
        scale.setRepeatCount(Animation.INFINITE);
        //渐变动画
        AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.7f);
        alpha.setDuration(800);
        scale.setRepeatMode(Animation.REVERSE);
        alpha.setRepeatCount(Animation.INFINITE);

        AnimationSet set = new AnimationSet(true);
        set.addAnimation(scale);
        set.addAnimation(alpha);

        dot.startAnimation(set);
    }

    private void regEvent(boolean b) {
        if (null != onlineLayout) {
            onlineLayout.setOnClickListener(b ? this : null);
        }
        if (null != cpscenterLayout) {
            cpscenterLayout.setOnClickListener(b ? this : null);
        }
        if (null != hn_btn_back) {
            hn_btn_back.setOnClickListener(b ? this : null);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.insurancereport_layout_online://网上定损理赔
                IntentInsuranceReportView intentView = new IntentInsuranceReportView(context, CreateAgreementbean, appCaseno, singlecar);
                intentView.setTypes(type);
                FrameworkManager.getInstance().showNewForm(context, intentView);
                break;
            case R.id.insurancereport_layout_cpscenter://理赔中心定损
                ServiceCenterView view = new ServiceCenterView(context, appCaseno);
                FrameworkManager.getInstance().showNewForm(context, view);
                break;
            case R.id.hn_btn_back:
                OnDestroy();
                closeForm();
                break;
            default:
                break;
        }
    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        regEvent(false);
        CreateAgreementbean = null;
        view = null;
    }
}
